<?php


    // Author: Tomasz Durka
    // Date: 5th February 2007
    // Prints out a link for PHP nails
    
    
  function toggle_link ($label, array $elements, array $params = array()) {

    
    $module = mod_suffix ? '/' . mod_suffix : '';
    $controller = module;
    $action = action;
    $parameter = false;
    $style = '';
    $class = '';
    $on_click = '';
    $id = '';
    
    if (!isset($params['action']) && module != $params['module']) {
      $action = false;
    }
    
    
    if (isset($params['active_if'])) {
      $active_if = $params['active_if'];
      if ($active_if)
        $class = ' class="active"';
    }
    
    foreach($params as $_key => $_val) {
      switch ($_key) {
        case 'parameter':
          $$_key = '/' . $_val;
          break;
        case 'class':
          if ($active_if)
            $$_key = " {$_key}=\"{$_val}_active\"";
          else
            $$_key = " {$_key}=\"{$_val}\"";
          break;
        case 'style':
        case 'id':
          $$_key = " {$_key}=\"{$_val}\"";
          break;
        case 'on_click':
          $$_key = " {$_val}; ";
          break;
        case 'url':
        case 'location':
          if ($_val ==  'back')
            $location = $_SERVER['HTTP_REFERER'];
          else
            $location = '/' . $_val;
          break;
        default:
          $$_key = $_val;
          break;
      }
    }
    
    $href = "toggle/" . join('/', $elements);
    $on_click = "$($(" . join('), $(', $elements) . ")).invoke('toggle');{$on_click}return false;";
    return "<a href=\"{$href}\" onClick=\"{$on_click}\" {$style}{$class}{$id}>{$label}</a>";
    
  }

?>